#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import sys
import requests
import pprint
from bs4 import BeautifulSoup

queryWord = sys.argv[1]
prtWord = queryWord.replace('+',' ')
print(prtWord)

reqWord = queryWord.replace('+','%20')
reqUrl = 'http://dict.youdao.com/w/eng/' + reqWord
req = requests.get(reqUrl)
#print(reqUrl)
html = req.text
soup = BeautifulSoup(html, 'html.parser')
div = soup.find(name='div', attrs={'class':'trans-container'})

if div:
    wordBuff=div.get_text()
    #print(wordBuff)
    wordBuff=wordBuff.replace('\t','')
    wordBuff=wordBuff.replace('\n','')
    #width need ' ' split
    wordBuff=wordBuff.replace("；"," ")
    wordBuff=wordBuff.replace('  ',' ')
    wordBuff=wordBuff.replace('   ',' ')
    wordBuff=wordBuff.replace('  ',' ')
    wordBuff=wordBuff.replace('  ',' ')
    printBuff=wordBuff.replace('  ',' ')
    printBuff.replace('\(','')
    printBuff.replace('\)','')
    printBuff.replace(u'uefbc','\n')
    #pprint.pprint(printBuff, width=40)
    pprint.pprint(printBuff, width=40, compact=True)
    #print(printBuff)
